<template>
	<view class="wrapper login">
		<div class="header center">
			<div class="flex1 tCenter f36 fbold">登录</div>
		</div>
		<text class="logo tCenter fbold f46">
			智慧停车系统
		</text>

		<u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm">
			<u-form-item prop="username">
				<u-input v-model="model1.username" border="none" placeholder="请输入用户名"></u-input>
			</u-form-item>
			<u-form-item prop="password">
				<u-input type="password" v-model="model1.password" border="none" placeholder="请输入密码"></u-input>
			</u-form-item>
			<div class="btheme center cfff f30" @click="submit">登录</div>
			<!-- <div class="center ctheme f30" @click="oauth2">微信一键登录</div> -->
		</u--form>
		<u-loading-page loading-mode="spinner" bg-color="rgba(0,0,0,.5)" loading-text="登陆中"
			:loading="loading"></u-loading-page>
	</view>
</template>

<script>
	import {
		baseUrl
	} from '@/utils/config.js'
	export default {
		data() {
			return {
				loading: false,
				agree: true,
				model1: {
					username: '',
					password: '',
				},
				rules: {
					'username': {
						type: 'string',
						required: true,
						message: '请填写手机号',
						trigger: ['blur']
					},
					'password': {
						type: 'string',
						required: true,
						message: '请输入密码',
						trigger: ['blur']
					},
				},
			}
		},
		onLoad(e) {
			// 如果一键登录直接获取信息
			if (e.userId) {
				this.getUserInfo(e.userId)
			}
		},
		methods: {
			getUserInfo(userId) {
				this.loading = true
				this.$http(`/api/user/info?userId=${userId}`).then(
					r => {
						this.loading = false
						uni.$u.toast('登陆成功')
						uni.setStorageSync('uinfo', r.data)
						this.open('/pages/index/index', 1)
					}).catch(e => {
					this.loading = false
				})
			},
			// 一键登录
			oauth2() {
				window.location.href = `${baseUrl}/api/oauth2`
			},
			submit() {
				this.$refs.uForm.validate().then(res => {
					if (this.agree) {
						this.GetLogin()
					} else {
						uni.$u.toast('')
					}

				})
			},
			GetLogin() {
				this.loading = true
				// this.$http(`/api/login`, this.model1,"GET").then(
				// 	r => {
				// 		this.loading = false
				uni.$u.toast('登陆成功')
				// uni.setStorageSync('uinfo', r.data)
				this.open('/pages/index/index', 1)
				// 	}).catch(e => {
				// 	this.loading = false
				// })
			}
		}
	}
</script>

<style lang="scss">
	.login {
		background: url();
		background-size: 100% 150%;

		:deep(.u-form-item__body__right__message) {
			margin-left: 0 !important;
		}

		.btheme {
			width: 662rpx;
			height: 100rpx;
			background: #066FFF;
			border-radius: 50rpx;
			margin-bottom: 36rpx;
		}

		:deep(.u-form-item__body) {
			padding: 30rpx 0;
		}

		:deep(.u-form-item) {
			width: 662rpx;
			background: #EFF4FA;
			border-radius: 50rpx;
			padding: 0 32rpx;
			margin-bottom: 32rpx;
		}

		:deep(.u-form) {
			padding: 144rpx 44rpx 0;
		}

		.logo {
			display: block;
			margin: 0 auto 60rpx;
			color: #666;
		}

		.header {
			padding: calc(var(--status-bar-height) + 20rpx) 32rpx 130rpx;

			.close-img {
				width: 26rpx;
				height: 26rpx;
			}
		}
	}
</style>